---
title: Agent with Vertex AI
---

## Code

```python cookbook/models/google/gemini/vertexai.py
"""
To use Vertex AI, with the Gemini Model class, you need to set the following environment variables:

export GOOGLE_GENAI_USE_VERTEXAI="true"
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="your-location"

Or you can set the following parameters in the `Gemini` class:

gemini = Gemini(
    vertexai=True,
    project_id="your-google-cloud-project-id",
    location="your-google-cloud-location",
)
"""

from agno.agent import Agent, RunOutput  # noqa
from agno.models.google import Gemini

agent = Agent(model=Gemini(id="gemini-2.0-flash-001"), markdown=True)

# Get the response in a variable
# run: RunOutput = agent.run("Share a 2 sentence horror story")
# print(run.content)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story")
```

## Usage

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Set up Vertex AI">
    Set your environment variables:
    ```bash
    export GOOGLE_GENAI_USE_VERTEXAI="true"
    export GOOGLE_CLOUD_PROJECT="your-project-id"
    export GOOGLE_CLOUD_LOCATION="your-location"
    ```
    
    Or configure in code:
    ```python
    gemini = Gemini(
        vertexai=True,
        project_id="your-google-cloud-project-id",
        location="your-google-cloud-location",
    )
    ```
  </Step>

  <Step title="Install libraries">
    ```bash
    pip install -U google-genai agno
    ```
  </Step>

  <Step title="Run Agent">
    <CodeGroup>
    ```bash Mac
    python cookbook/models/google/gemini/vertexai.py
    ```

    ```bash Windows
    python cookbook/models/google/gemini/vertexai.py
    ```
    </CodeGroup>
  </Step>
</Steps>